package cate.game.activity.specall;

import cate.common.table.activity.specall.row.SpeCallPosterRow;
import cate.common.table.d.GDFunc;
import cate.game.activity.base.core.SubActivitySingle;
import cate.game.activity.specall.msg.SpeCallPosterDataResp;
import cate.game.res.MixRes;
import cate.game.role.task.TaskGroup;
import com.fasterxml.jackson.annotation.JsonIgnore;
import easy.java.dev.note.NoteClass;
import easy.java.dev.note.NoteField;
import easy.java.practice.errorcode.EcResult;

@NoteClass("海报")
public class SpeCallPoster extends SubActivitySingle<SpeCallActivity> {
    @NoteField("是否领取了终极大奖")
    public boolean gotBigPrize;

    public void clear() {
        gotBigPrize = false;
    }

    @JsonIgnore
    public EcResult<Void> getBigPrize() {
        EcResult<Void> r = new EcResult<>();
        if (gotBigPrize) {
            return r.fail("奖励已领取");
        }
        SpeCallPosterRow posterRow = role.getGame().table.speCall.poster.getRow(parent.configTid());
        if (posterRow == null) {
            return r.fail("活动已结束");
        }
        TaskGroup group = role.getTask().getGroup(GDFunc.SPE_CALL_TASK);
        if (group == null) {
            return r.fail("无法领取该奖励");
        }
        if (group.isDoneEmpty() || !group.ingList.isEmpty()) {
            return r.fail("请先完成其他任务");
        }
        gotBigPrize = true;
        MixRes reward = new MixRes(posterRow.rewardStr);
        reward.add(role, true);
        role.getGame().notice.dialogReward(role, reward);
        noticeUpdate();
        return r;
    }

    public void noticeUpdate(){
        role.sendNow(new SpeCallPosterDataResp(this));
    }
}
